
import {Button,Modal,message,Spin} from 'antd';
import {WeaDialog,WeaTab,WeaNewScroll,WeaRightMenu,WeaLocaleProvider,WeaFormItem,WeaInput,WeaSearchGroup } from 'ecCom';
import {observer} from "mobx-react";
import * as  Apis from '../../apis/project';
import WbsFieldSet from '../common/wbsFieldSet'
const getLabel = WeaLocaleProvider.getLabel;

@observer
class WbsFieldSetDialog extends React.Component {
    constructor(props) {
        super(props);
        this.state={
            width:700,
            height:500,
            isDisabled: false
        }
    }
    componentDidMount(){
        this.computedWH();
    }
    computedWH=()=>{
        const screenWidth = document.body.clientWidth;
        const screenHeight = document.body.clientHeight;
        if(screenWidth <= 700){
            this.setState({width:screenWidth,})
        }
        if(screenHeight <= 500){
            this.setState({ height :screenHeight})
        }
    }
    
    render() {
        const prjImportStore = this.props.contentStore;
        const {visible} = prjImportStore;
       const { width,height} = this.state;
        return (
            <div>
                <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@k0kdtr`}
                    title= {getLabel(516151,"WBS导入字段配置")}
                    visible={visible}
                    style= {{width: width, height: document.body.clientHeight -270}}
                    maskClosable={false}
                    icon="icon-coms-project"
                    iconBgcolor="#217346"
                    onCancel={()=>prjImportStore.handleDialog(false)}
                    buttons={this.getDialogButtons()}
                >
                    <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@oldees`} datas={this.getRightMenu()} >
                        <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@nqpdgl`} height={document.body.clientHeight - 300+"px"}> 
                            <WbsFieldSet ecId={`${this && this.props && this.props.ecId || ''}_WbsFieldSet@74fnoj`}  ref={el => {this.wbs = el}}  wbsStore={prjImportStore}/>  
                        </WeaNewScroll>
                    </WeaRightMenu>
                </WeaDialog>
            </div>
        )
    }

    getDialogButtons(){
        const {contentStore} = this.props;
        const {saveVisible} = contentStore;
        let btn = [];
        btn.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@m3d981@save`}  type="primary" disabled={saveVisible} onClick={()=>{this.wbs.wbsFieldSet.showErrors();contentStore.saveTaskWbsField();}}>{getLabel(86,"保存")}</Button>);
        btn.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@rue8y4@close`}  type="primary" onClick={()=>contentStore.handleDialog(false)}>{getLabel(309,"关闭")}</Button>);
        return btn
    }

    getRightMenu() {
        const {contentStore} = this.props;
        const {saveVisible} = contentStore;
        let btns = [];
        btns.push({
            key: "taskwbssave",
            icon: <i className='icon-coms-Preservation' />,
            content: getLabel(86,"保存"),
            disabled: saveVisible,
            onClick : () => {
                this.wbs.wbsFieldSet.showErrors();
                contentStore.saveTaskWbsField();
            }
        });
        btns.push({
            key: "taskwbsadd",
            icon: <i className='icon-coms-Batch-add' />,
            content: getLabel(611,"添加"),
            onClick: () => {
                this.wbs.wbsFieldSet.doAdd();
            }
        });
        btns.push({
            key: "taskwbsdel",
            icon: <i className='icon-coms-delete' />,
            content: getLabel(91,"删除"),
            onClick: () => {
                this.wbs.wbsFieldSet.doDelete();
            }
        });
        return btns;
    }
}

export default WbsFieldSetDialog;